package com.yidu.BusinessData.service.impl;

import com.yidu.BusinessData.entity.Broker;
import com.yidu.BusinessData.entity.CashEntity;
import com.yidu.BusinessData.entity.Exchange;
import com.yidu.BusinessData.mapper.ExchangeMapper;
import com.yidu.BusinessData.service.ExchangeServce;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ExchangeImpl implements ExchangeServce {
    @Resource
    ExchangeMapper exchangeMapper;

    @Override
    public int selectCount() {
        return exchangeMapper.selectCount();
    }

    /**
     * 重写条件查询的方法
     * @param exchange
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<Exchange> selectExchange(Exchange exchange, int page, int limit) {
        HashMap map = new HashMap();
        map.put("splicing",splicing(exchange));
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return exchangeMapper.selectExchange(map);
    }

    @Override
    public int selectExchangeFlag(Exchange exchange) {
        int i = exchangeMapper.selectExchangeFlag(exchange);
        return i;
    }

    /**
     * 重写增加数据的方法
     * @param exchange
     * @return
     */
    @Override
    public int insertExchange(Exchange exchange) {
        return exchangeMapper.insertExchange(exchange);
    }

    @Override
    public int deleteExchange(Exchange exchange) {
        return exchangeMapper.deleteExchange(exchange);
    }

    @Override
    public int updateExchange(Exchange exchange) {
        return exchangeMapper.updateExchange(exchange);
    }


    public String splicing(Exchange exchange){
        StringBuffer str = new StringBuffer("");
        if (exchange.getExchangeName()!=null && !exchange.getExchangeName().equals("")){
            str.append(" and exchangeName="+exchange.getExchangeName());
        } if (exchange.getExchangeType()!= null && !exchange.getExchangeType().equals("")){
            str.append(" and exchangeType="+exchange.getExchangeType());
        } else {
            str.append(" and exchangeName LIKE '%"+exchange.getExchangeName()+"%'");
        }
        return str.toString();
    }
}
